package com.wz.project.cxtj.viewInHistory.controller;

import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.framework.web.page.TableDataInfo;
import com.wz.project.cxtj.viewInHistory.domain.ViewInHistory;
import com.wz.project.cxtj.viewInHistory.service.IViewInHistoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 入库单据历史Controller
 * 
 * @author wz
 * @date 2022-05-20
 */
@Controller
@RequestMapping("/search/viewInHistory")
public class ViewInHistoryController extends BaseController
{
    private String prefix = "cxtj/viewInHistory";

    @Autowired
    private IViewInHistoryService viewInHistoryService;

    @RequiresPermissions("search:viewInHistory:view")
    @GetMapping()
    public String viewInHistory()
    {
        return prefix + "/viewInHistory";
    }

    /**
     * 查询入库单据历史列表
     */
//    @RequiresPermissions("search:viewInHistory:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ViewInHistory viewInHistory)
    {
        startPage();
        List<ViewInHistory> list = viewInHistoryService.selectViewInHistoryList(viewInHistory);
        return getDataTable(list);
    }

    /**
     * 导出入库单据历史列表
     */
//    @RequiresPermissions("search:viewInHistory:export")
    @Log(title = "入库单据历史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ViewInHistory viewInHistory)
    {
        List<ViewInHistory> list = viewInHistoryService.selectViewInHistoryList(viewInHistory);
        ExcelUtil<ViewInHistory> util = new ExcelUtil<ViewInHistory>(ViewInHistory.class);
        return util.exportExcel(list, "viewInHistory");
    }

    /**
     * 新增入库单据历史
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存入库单据历史
     */
    @RequiresPermissions("search:viewInHistory:add")
    @Log(title = "入库单据历史", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ViewInHistory viewInHistory)
    {
        return toAjax(viewInHistoryService.insertViewInHistory(viewInHistory));
    }

    /**
     * 修改入库单据历史
     */
    @GetMapping("/edit/{stockinId}")
    public String edit(@PathVariable("stockinId") String stockinId, ModelMap mmap)
    {
        ViewInHistory viewInHistory = viewInHistoryService.selectViewInHistoryById(stockinId);
        mmap.put("viewInHistory", viewInHistory);
        return prefix + "/edit";
    }

    /**
     * 修改保存入库单据历史
     */
    @RequiresPermissions("search:viewInHistory:edit")
    @Log(title = "入库单据历史", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ViewInHistory viewInHistory)
    {
        return toAjax(viewInHistoryService.updateViewInHistory(viewInHistory));
    }

    /**
     * 删除入库单据历史
     */
    @RequiresPermissions("search:viewInHistory:remove")
    @Log(title = "入库单据历史", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(viewInHistoryService.deleteViewInHistoryByIds(ids));
    }
}
